package com.ruoyi.attendance.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.course.domain.CourseRecord;
import com.ruoyi.course.service.ICourseRecordService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.attendance.domain.SignRecord;
import com.ruoyi.attendance.service.ISignRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 签到Controller
 * 
 * @author Weiney
 * @date 2025-03-04
 */
@RestController
@RequestMapping("/attendance/sign")
public class SignRecordController extends BaseController
{
    @Autowired
    private ISignRecordService signRecordService;

    /**
     * 查询签到列表
     */
    @PreAuthorize("@ss.hasPermi('attendance:sign:list')")
    @GetMapping("/list")
    public TableDataInfo list(SignRecord signRecord)
    {
        startPage();
        List<SignRecord> list = signRecordService.selectSignRecordList(signRecord);
        return getDataTable(list);
    }


    /**
     * 导出签到列表
     */
    @PreAuthorize("@ss.hasPermi('attendance:sign:export')")
    @Log(title = "签到", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SignRecord signRecord)
    {
        List<SignRecord> list = signRecordService.selectSignRecordList(signRecord);
        ExcelUtil<SignRecord> util = new ExcelUtil<SignRecord>(SignRecord.class);
        util.exportExcel(response, list, "签到数据");
    }

    /**
     * 获取签到详细信息
     */
    @PreAuthorize("@ss.hasPermi('attendance:sign:query')")
    @GetMapping(value = "/{signId}")
    public AjaxResult getInfo(@PathVariable("signId") Long signId)
    {
        return success(signRecordService.selectSignRecordBySignId(signId));
    }

    /**
     * 新增签到
     */
    @PreAuthorize("@ss.hasPermi('attendance:sign:add')")
    @Log(title = "签到", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SignRecord signRecord)
    {
        signRecord.setUserId(getUserId());
        signRecord.setDeptId(getDeptId());
        return toAjax(signRecordService.insertSignRecord(signRecord));
    }

    /**
     * 修改签到
     */
    @PreAuthorize("@ss.hasPermi('attendance:sign:edit')")
    @Log(title = "签到", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SignRecord signRecord)
    {
        return toAjax(signRecordService.updateSignRecord(signRecord));
    }

    /**
     * 删除签到
     */
    @PreAuthorize("@ss.hasPermi('attendance:sign:remove')")
    @Log(title = "签到", businessType = BusinessType.DELETE)
	@DeleteMapping("/{signIds}")
    public AjaxResult remove(@PathVariable Long[] signIds)
    {
        return toAjax(signRecordService.deleteSignRecordBySignIds(signIds));
    }
}
